// import { mapState } from 'vuex'
// const menuList = th
import constDef from 'assets/js/const'
const routes = [

  {
    path: '/',
    component: () => import('layouts/BlogsMainLayout'),
    children: [
      { path: '', component: () => import('pages/blogs/blogsIndex') },
      {
        path: constDef.menuUrls.BLOGS_RECOMMEND,
        component: () => import('pages/blogs/menus/recommend')
      },
      {
        path: constDef.menuUrls.PERSONAL_CENTER,
        component: () => import('pages/blogs/menus/personal')
      },
      {
        path: constDef.menuUrls.NOTE_LIST,
        component: () => import('pages/blogs/menus/nodelist')
      },
      {
        path: constDef.menuUrls.ARCHIVED_FILE,
        component: () => import('pages/blogs/menus/archived')
      }
    ]
  },
  // 管理平台路由
  {
    path: '/manage',
    component: () => import('layouts/ManageMainLayout'),
    beforeEnter: (to, from, next) => {
      if (sessionStorage.getItem('token')) { // 判断本地是否存在access_token
        next()
      } else {
        next({
          path: '/login'
        })
      }
      /* 如果本地 存在 token 则 不允许直接跳转到 登录页面 */
      if (to.fullPath === '/login') {
        if (sessionStorage.getItem('token')) {
          next({
            path: from.fullPath
          })
        } else {
          next()
        }
      }
    },
    children: [
      { path: '', component: () => import('pages/manage/manageIndex') },
      {
        path: constDef.menuUrls.USER_MANAGE,
        component: () => import('pages/manage/menus/userManage')
      },
      {
        path: constDef.menuUrls.FILE_LIST,
        component: () => import('pages/manage/menus/fileList')
      },
      {
        path: constDef.menuUrls.ADD_NODE_TOOL,
        component: () => import('pages/manage/menus/addNodeTool')
      },
      {
        path: constDef.addNodeToolUrls.ADD_NODE,
        component: () => import('pages/manage/tools/addnodetype')
      },
      {
        path: constDef.addNodeToolUrls.ADD_NODE_TYPE,
        component: () => import('pages/manage/tools/addnode')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('layouts/LoginLayout.vue')
  }

]

// Always leave this as last one
if (process.env.MODE !== 'ssr') {
  routes.push({
    path: '*',
    component: () => import('pages/Error404.vue')
  })
}

export default routes
